package com.san.metadata.task;

import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.san.common.utils.Constant;
import com.san.metadata.dao.OperationMetadataManager;
import com.san.metadata.domain.BusinessDataDO;

/**
 * 固化业务元数据通用调度线程
 * 
 * @author xiangyz
 *
 */
public class FixingBusiMetadatahread extends Thread {

	private static final Logger logger = LoggerFactory.getLogger(FixingBusiMetadatahread.class);

	private OperationMetadataManager operationMetadataManager;

	private List<BusinessDataDO> list;

	public FixingBusiMetadatahread(OperationMetadataManager operationMetadataManager, List<BusinessDataDO> list) {
		this.operationMetadataManager = operationMetadataManager;
		this.list = list;
	}

	@Override
	public void run() {
		Date date = new Date();
		Long batchNo = date.getTime();
		for (BusinessDataDO businessDataDO : list) {
			if (businessDataDO.getDelFlag() == Constant.DEL_FLAG_NORMAL) {
				if (businessDataDO.getDataType() == Constant.BUSINESS_DATA_TYPE_LEGAL_PERSON) {
					
					operationMetadataManager.fixingLegalBusiMetadata(batchNo, businessDataDO);
				} else if (businessDataDO.getDataType() == Constant.BUSINESS_DATA_TYPE_NATURAL_PERSON) {
					
					operationMetadataManager.fixingNaturalBusiMetadata(batchNo, businessDataDO);
				} else {
					logger.error("业务元数据固化，未知数据类型，业务元数据id：" + businessDataDO.getBusiId());
				}
			}
			
		}
	}

}
